/*
 ============================================================================
 Name		: VoiceEngine.h
 Author	  : William Zhang
 Version	 : 1.0
 Copyright   : all rights reserved.
 Description : CVoiceEngine declaration
 ============================================================================
 */

#ifndef VOICEENGINE_H
#define VOICEENGINE_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>
#include <VoIPUtilityFactory.h>
#include <VoIPDownlinkStream.h>
#include <VoIPUplinkStream.h>
#include <VoIPFormatIntfc.h>
#include <VoIPDataBuffer.h>

// CLASS DECLARATION

/**
 *  CVoiceEngine
 * 
 */
class CVoiceEngine : public CBase
					 public MVoIPDownlinkObserver,
                     public MVoIPUplinkObserver,
                     public MVoIPFormatObserver,
	{
public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~CVoiceEngine();

	/**
	 * Two-phased constructor.
	 */
	static CVoiceEngine* NewL();

	/**
	 * Two-phased constructor.
	 */
	static CVoiceEngine* NewLC();

private:

	/**
	 * Constructor for performing 1st stage construction
	 */
	CVoiceEngine();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL();

public:
	
	/**
	 * Initialize Downlink stream and Uplink stream
	 * 
	 */
	void Init();
	

private:
	
	/**
	 * Initialize Uplink stream
	 */
	void InitUp();
	
	/**
	 * set downlink format
	 */
	void SetUpFormat(TVoIPCodecFormat aFormat);
	
	
	/**
	 * Initialize Downlink stream
	 */
	void InitDn();
	
	/**
	 * set downlink format
	 */
	void SetDnFormat(TVoIPCodecFormat aFormat);
	
public:
	//dereved from MVoIPDownlinkObserver
    /**
     * ?description
     *
     * @since S60 v?.?
     * @param const CVoIPAudioDownlinkStream&
     * @param CVoIPDataBuffer*
     * @return void
     */
    void FillBuffer(const CVoIPAudioDownlinkStream& aSrc,
                            CVoIPDataBuffer* aBuffer);
    /**
     * ?description
     *
     * @since S60 v?.?
     * @param const CVoIPAudioDownlinkStream&
     * @param TInt - Event type
     * @param TInt - Status
     * @return void
     */
    void Event(const CVoIPAudioDownlinkStream& aSrc,
                       TInt aEventType,
                       TInt aError);
    
public:
    //derived from MVoIPUplinkObserver
    /**
     * ?description
     *
     * @since S60 v?.?
     * @param CVoIPAudioUplinkStream&
     * @param TPtr8
     * @return void
     */
    void EmptyBuffer(const CVoIPAudioUplinkStream& aSrc,
                             CVoIPDataBuffer* aBuffer);

    /**
     * ?description
     *
     * @since S60 v?.?
     * @param CVoIPAudioUplinkStream&
     * @param TInt - Event type
     * @param TInt - Status
     * @return void
     */
    void Event(const CVoIPAudioUplinkStream& aSrc,
                       TInt aEventType,
                       TInt aError); 
    
public:
    //derived from MVoIPFormatObserver
    /**
     * ?description
     *
     * @since S60 v?.?
     * @param const CVoIPFormatIntfc&
     * @param TInt - event type
     * @return void
     */
    void Event(const CVoIPFormatIntfc& aSrc, TInt aEventType);

    
private:
    CVoIPUtilityFactory*        iFactory;
    CVoIPAudioDownlinkStream*   iVoiceDnlink;
    CVoIPAudioUplinkStream*     iVoiceUplink;

    CVoIPFormatIntfc* iDnFormat;
    CVoIPFormatIntfc* iUpFormat;
    
    //voice buffer
    CVoIPDataBuffer*  iSendVoiceBuf;
    CVoIPDataBuffer*  iRecvVoiceBuf;
	};

#endif // VOICEENGINE_H
